<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//商品控制器
class GoodsController extends CommonController{
	private $model;
	public function __auto(){
	    $this->model = new \Common\Model\Goods;
	}
	public function index(){
		$data = $this->model->get();
		View::with('data',$data);
	    View::make();
	}
	//商品添加
	public function add(){
		if(IS_POST){
			//p($_POST);die;
			if($this->model->store()){
				View::success('添加成功',U('index'));
			}
			View::error($this->model->getError());
		}
		//处理分类
		$cateModel = new \Common\Model\Cate;
		//View::with('cate',$cateModel->get());
		View::with('cateData',Data::tree($cateModel->get(),'cname'));
		//处理品牌
		$brandModel = new \Common\Model\Brand;
		View::with('brandData',$brandModel->get());
	    View::make();
	}
	//
	public function ajaxGetAttr(){
	    $tid = $_POST['tid'];
		$typeAttrModel = new \Common\Model\TypeAttr;
		$data = $typeAttrModel->where("ygshop_type_tid",$tid)->get();
		foreach ($data as $key => $value) {
			$data[$key]['tavalue']=explode(',', $value['tavalue']);
		}
		View::ajax($data);
	}
	//异步上传图片
	public function ajaxUpload(){
	    $file = Upload::Path("Upload/" . date("ymd"))->make();
		View::ajax($file[0]);
	}
	//异步删除图片
	public function ajaxDelImg(){
	    if(unlink($_POST['url'])){
	    		View::ajax(1);
	    }else{
	    		View::ajax(0);
	    }
	}
}



 ?>